/*
 * @Author: sean_kei@163.com
 * @Date: 2021-06-08 15:07:29
 * @LastEditors: sean_kei@163.com
 * @LastEditTime: 2021-11-12 10:33:56
 */
package com.wxhandle.cleandemo.application.services;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

import javax.transaction.Transactional;

import com.wxhandle.cleandemo.core.domain.identity.SysClaim;
import com.wxhandle.cleandemo.core.domain.identity.SysRole;
import com.wxhandle.cleandemo.core.services.SysRoleService;
import com.wxhandle.cleandemo.persistence.repositorys.identity.SysClaimRepository;
import com.wxhandle.cleandemo.persistence.repositorys.identity.SysRoleRepository;


@Service
public class SysRoleServiceImpl extends DomainServiceImpl<SysRole, Long> implements SysRoleService {
    
    @Lazy
    @Autowired
    private SysRoleRepository repository;

    @Lazy
    @Autowired
    private SysClaimRepository claimRepository;

    @Override
    @Transactional
    public void updatePermission(Long id, String[] perms) {
        List<SysClaim> claims = claimRepository.findAllById(Arrays.asList(perms));

        SysRole role = repository.getById(id);
        role.UpdatePermissions(claims);
        repository.save(role);
    }

}
